package test;
import java.util.*;
class PersonSortable implements Comparable<PersonSortable>{
	private String name;
	private int age;
	

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}
	
	public PersonSortable(String name,int age){
		super();
		this.name = name;
		this.age = age;
	}
	
	@Override
	public String toString() {
		return name +"-" + age ;
	}
	@Override
	public int compareTo(PersonSortable o) {
		int temp = this.getName().compareTo(o.getName());
		if(temp!=0)
			return temp;
		if(this.getAge()<o.getAge())
			return -1;
		if(this.getAge()>o.getAge())
			return 1;
		return 0;
	}
	
}

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		while(in.hasNext()){
			PersonSortable[] persons = new PersonSortable[n];
			for (int i = 0; i < n; i++) {
				 persons[i] = new PersonSortable(in.next(), in.nextInt());
			}
			 Arrays.sort(persons);
			for (int i = 0; i < persons.length; i++) {
				System.out.println(persons[i]);
			}
			System.out.println(Arrays.toString(PersonSortable.class.getInterfaces()));
		}
	}

}
